package com.starblink.android.guang.widget.cstnavbar


import  com.starblink.android.basic.R
import com.starblink.android.basic.user.UserDataCenter
import com.starblink.basic.storage.SkStorage
import com.starblink.basic.util.CommUtils

object CustomNavBarConfig {


    val btmNavImgFirstResNormal =
        R.drawable.acts_dft_btm_nav_1_sel
    private val btmNavImgFirstResUnSel =
        R.drawable.acts_dft_btm_nav_1_unsel
    private val btmNavImgFirstResTop =
        R.drawable.acts_dft_btm_nav_1_sel_top
    private val btmNavImgThirdResNormal =
        R.drawable.acts_dft_btm_nav_3_sel
    private val btmNavImgThirdResNotify =
        R.drawable.acts_dft_btm_nav_3_sel_notify

    private val btmNavImgResArrSel = arrayListOf(
        btmNavImgFirstResNormal,
        R.drawable.acts_dft_btm_nav_2_sel,
        btmNavImgThirdResNormal,
        R.drawable.acts_dft_btm_nav_4_sel
    )
    private val btmNavImgResArrUnSel = arrayListOf(
        btmNavImgFirstResUnSel,
        R.drawable.acts_dft_btm_nav_2_unsel,
        R.drawable.acts_dft_btm_nav_3_unsel,
        R.drawable.acts_dft_btm_nav_4_unsel
    )

    private val firstArrSel = arrayListOf(
        btmNavImgFirstResNormal,
        btmNavImgFirstResTop
    )


    var currentImgResData = arrayListOf(
        CtmNavBarItemData(0),
        CtmNavBarItemData(1),
        CtmNavBarItemData(2),
        CtmNavBarItemData(3)
    )
    var mShowTopImg = false

    var isNewDay = false
        set(value) {
            field = value
            handleThirdBtn(field)
        }


    fun initNavBtm() {
        UserDataCenter.currentIndex = 0
        //是否是同一天
        initNavBtmWhoBeChoice()
    }


    /**
     * 消息按钮今天已经点过了
     */
    private fun thirdBtnTodayHasClick() {
        if (isNewDay) {
            isNewDay = false
            UserDataCenter.updateDay()
        }
    }


    /**
     * 初始化个按钮状态
     */
    private fun initNavBtmWhoBeChoice() {
        //第一个
        handleFirstBtn(mShowTopImg, true)
        //第2个
        handleOtherBtn(1)
        //第3个
        handleThirdBtn(isNewDay)
        //第4个
        handleOtherBtn(3)
    }

    fun setNavBtmWhoBeChoice(
        index: Int
    ): ArrayList<CtmNavBarItemData> {
        when (index) {
            0 -> {
                //第一个
                handleFirstBtn(mShowTopImg, true)
                //第2个
                handleOtherBtn(1)
                //第3个
                handleThirdBtn(isNewDay)
                //第4个
                handleOtherBtn(3)
            }

            1 -> {
                handleFirstBtn(mShowTopImg)
                handleOtherBtn(1, true)
                handleThirdBtn(isNewDay)
                handleOtherBtn(3)
            }

            2 -> {
                //重置小红点
                thirdBtnTodayHasClick()
                handleFirstBtn(mShowTopImg)
                handleOtherBtn(1)
                handleThirdBtn(isNewDay, true)
                handleOtherBtn(3)
            }

            3 -> {
                handleFirstBtn(mShowTopImg)
                handleOtherBtn(1)
                handleThirdBtn(isNewDay)
                handleOtherBtn(3, true)
            }
        }

        return currentImgResData
    }

    private fun handleFirstBtn(showTopImg: Boolean, isClick: Boolean = false) {
        var data = currentImgResData[0]
        data.clearData()
        data.index = 0
        data.normalRes = btmNavImgResArrUnSel[0]
        data.firstChoiceResArr = firstArrSel
        if (isClick) {
            if (showTopImg) {
                data.showTop = true
                data.clicked = true
            } else {
                data.clicked = true
            }
        }
    }

    private fun handleThirdBtn(showNotifyImg: Boolean, isClick: Boolean = false) {
        var data = currentImgResData[2]
        data.clearData()
        data.index = 2
        if (isClick) {
            data.clicked = true
            data.normalRes = btmNavImgResArrSel[2]
        } else {
            if (showNotifyImg) {
                data.showNotify = true
                data.normalRes = btmNavImgThirdResNotify

            } else {
                data.showNotify = true
                data.normalRes = btmNavImgResArrUnSel[2]
            }
        }
    }

    private fun handleOtherBtn(index: Int, isClick: Boolean = false) {
        var data = currentImgResData[index]
        data.clearData()
        data.index = index
        data.normalRes = if (isClick) btmNavImgResArrSel[index] else btmNavImgResArrUnSel[index]
    }
}